package vivek.project.pocketmoney.common.utils
{
	import flash.data.SQLConnection;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import vivek.project.pocketmoney.common.CommonData;

	public class CommonUtils
	{
		public static const fyMonthStart:int=04;
		public static function isFinancialYear(date:Date, fy:int):Boolean
		{
			var startDate:Date=new Date(fy, fyMonthStart - 1, 1);
			var endDate:Date=new Date(fy + 1, fyMonthStart - 2, 31);
			if (date.time >= startDate.time && date.time <= endDate.time)
				return true;
			else
				return false;
			return false;
		}
		public static function getHTTPPageProperties(url:String):String
		{
			var object:Object=new Object();
			var navUrl:String="http://www.citibank.co.in/";
			var finalArray:Array=new Array();
			var textLoader:URLLoader=new URLLoader();
			var textReq:URLRequest=new URLRequest(navUrl);
			textReq.method=URLRequestMethod.GET;
			//textReq.data = variables;
			textLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);
			textLoader.addEventListener(IOErrorEvent.IO_ERROR, doEvent);
			textLoader.addEventListener(Event.COMPLETE, doEvent);
			textLoader.load(textReq);
			return finalArray.toString();
		}
		private static function doEvent(evt:Event):void
		{
			switch (evt.type)
			{
				case Event.COMPLETE: /* If the load was successful, create a URLVariables object from the URLLoader.data property and populate the paramColl ArrayCollection object. */
					var ldr:URLLoader=evt.currentTarget as URLLoader;
					//URLData=ldr.data;
					//getLatestNAVValue();
					//var values:Array=URLData.split("\n");
					//var array:Array=new Array();
					//	mutualFundModel.addMFNAVBlockToHistory(array);
					break;
				case IOErrorEvent.IO_ERROR:
				{
					//PMLogger.logMisc("MFDATAFETCH", evt.toString(), mfid + startDate.toDateString() + endDate.toDateString());
					//trace(mfid + evt.toString() + ", Could not be updated, From : " + startDate.toDateString() + " End Date : " + startDate.toDateString());
					break;
				}
			}
		}
		public function CommonUtils()
		{
		}
		public static function getEMI(amount:Number, rate:Number, duration:Number):Number
		{
			//=C5*D6*POWER((1+D6),D7)/(POWER(1+D6,D7)-1)
			rate=rate / 1200;
			var emi:Number=amount * rate * Math.pow((1 + rate), duration) / (Math.pow(1 + rate, duration) - 1);
			//emi = new Number(CommonData.getNumberFormatter().format(emi));
			return emi;
		}
		public static function getInterest(rate:Number, emi:Number):Number
		{
			var interestComp:Number=(rate * emi) / 1200;
			return interestComp;
		}
		public static function getPricipal(rate:Number, emi:Number):Number
		{
			var interestComp:Number=(rate * emi) / 1200;
			return emi - interestComp;
		}
		public static function loadFileFromStorage(file:String, delimiter:String):String
		{
			var arrayList:Array=new Array();
			var sqlFile:File=File.applicationStorageDirectory.resolvePath(file);
			var _sqlConnection:SQLConnection;
			if (sqlFile.exists)
			{
				var fileStream:FileStream=new FileStream();
				fileStream.open(sqlFile, FileMode.READ);
				var fileInfo:String=fileStream.readUTFBytes(fileStream.bytesAvailable);
				fileStream.close();
			}
			return fileInfo;
		}
	}
}